package com.dailyblue.java.standard.design.代理模式;

import com.dailyblue.java.standard.design.代理模式.cglib动态代理.CGLibDynamicProxy;
import com.dailyblue.java.standard.design.代理模式.jdk动态代理.JDK1DynamicProxy;
import com.dailyblue.java.standard.design.代理模式.jdk动态代理.JDK2DynamicProxy;
import com.dailyblue.java.standard.design.代理模式.静态代理.Secretary;

import java.lang.reflect.Proxy;

public class App {

    public static void a(){
        Boss boss = new Boss();
        Treat treat = new Secretary(boss);
        treat.treat();
    }

    public static void b(){
        Boss boss = new Boss();
        JDK1DynamicProxy dp = new JDK1DynamicProxy(boss);
        Treat treat = (Treat)Proxy.newProxyInstance(Treat.class.getClassLoader(),new Class[]{Treat.class},dp);
        treat.treat();
        System.out.println(treat);
    }

    public static void c(){
        Boss boss = new Boss();
        CGLibDynamicProxy c = new CGLibDynamicProxy();
        Treat obj = (Treat) c.getInstance(boss);
        obj.treat();
    }

    public static void d(){
        JDK2DynamicProxy jdk2 = new JDK2DynamicProxy();
        Treat treat = jdk2.getMapper(Treat.class);
        treat.treat();
    }

    public static void e(){
        JDK2DynamicProxy proxy = new JDK2DynamicProxy();
        EmpMapper mapper = proxy.getMapper(EmpMapper.class);
        mapper.save();
    }
    public static void main(String[] args) {
        e();
    }
}
